/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import java.util.List;
import POJO.*;
import java.sql.SQLException;

/**
 *
 * @author Master
 */
public class DAO_DangNhap {
    private String quyen;
    public boolean temp = false;
    
    public boolean DangNhap(String tentk, String matkhau) throws SQLException{        
        DAO_TaiKhoan taiKhoan = new DAO_TaiKhoan();
        List<POJO_TaiKhoan> dn = taiKhoan.LoadList();
        DataProvider data = new DataProvider();
        
        for(POJO_TaiKhoan taiKhoan1 : dn){
            String str = data.MD5(matkhau + taiKhoan1.getNgaytao());
            if((taiKhoan1.getTentk() == null ? tentk == null : taiKhoan1.getTentk().equals(tentk)) && (taiKhoan1.getMatkhau() == null ? str == null : taiKhoan1.getMatkhau().equals(str))){
                temp = true;
                quyen = taiKhoan1.getQuyen();
            }
            else{
                temp = false;
            }
        }
        return temp;
    }
    
    public String SendLevel(){
        return this.quyen;
    }
}
